package ug.co.icom.kyazze.healthticket;

import ug.co.icom.kyazze.healthticket.data.MinUser;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

public class SRAdapter extends ArrayAdapter<MinUser> {

	private Context context;
	private MinUser[] users;
	public SRAdapter(Context context, int resource, int textViewResourceId,
			MinUser[] objects) {
		super(context, resource, textViewResourceId, objects);
		this.context = context;
		this.users = objects;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		View row = inflater.inflate(R.layout.searchitem_layout, parent, false);
		
		TextView title = (TextView) row.findViewById(R.id.textView1);
		Button button = (Button) row.findViewById(R.id.requestConn);
		
		title.setText(getFullName(position));
		button.setTag(users[position]);
		
		return row;
	}

	private String getFullName(int position) {
		String toReturn = "";
		
		toReturn += users[position].FirstName;
		if(!users[position].LastName.equals(""))
		{
			toReturn += " "+users[position].LastName;
		}
		if(!users[position].OtherNames.equals(""))
		{
			toReturn += " "+users[position].OtherNames;			
		}
		
		return toReturn;
	}

}
